﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartApplication.Api.Applient.Command.Process;
using SmartApplication.Api.Dto;
using SmartApplication.ApiCode;

namespace SmartApplication.Api.Controllers
{
    /// <summary>
    /// 深加工控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        public ProcessController(IMediator mediator)
        {
            Mediator = mediator;
        }

        public IMediator Mediator { get; }


        /// <summary>
        /// 显示深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ProcessDto>>> ListProcess([FromQuery]ListProcessCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 添加深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddProcess(AddProcessCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 修改深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateProcess(UpdateProcessCommand request)
        {
            return await Mediator.Send(request);
        }
    }
}
